package com.zyj.benchmark.test.formap;


import cn.hutool.core.util.RandomUtil;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 1, time = 2, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 1, time = 2, timeUnit = TimeUnit.SECONDS)
@State(Scope.Thread)
@Fork(1)
public class EnumMatchBenchmark {

    int value = -1;

    @Setup(Level.Invocation)
    public void prepareValue() {
        value = RandomUtil.randomInt(1, 4);
    }

    @Benchmark
    public EnumMatch matchByFor() {
        return EnumMatch.matchWithFor(value);
    }

    @Benchmark
    public EnumMatch matchByMap() {
        return EnumMatch.matchWithMap(value);
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(EnumMatchBenchmark.class.getSimpleName())
                .build();
        new Runner(opt).run();
    }

}
